/**
 *
 * @author 
 *
 */
class Scene extends egret.DisplayObjectContainer {
    
    //private bg: egret.Bitmap;
    //private map: egret.Bitmap;
    
    private soldier: Soldier;
    
    public constructor() {
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onAddToStage,this);
	}
	
    private onAddToStage(event: egret.Event) {
        //创建一个计时器对象
        var timer: egret.Timer = new egret.Timer(500,30);
        //注册事件侦听器
        timer.addEventListener(egret.TimerEvent.TIMER,this.Update,this);
        timer.addEventListener(egret.TimerEvent.TIMER_COMPLETE,this.UpdateComplete,this);
        //开始计时
        //timer.start();
        //var stageW: number = _width;
        //var stageH: number = _height;

        var bgImage: egret.Bitmap = this.createBitmapByName("bg1Image");
        this.addChild(bgImage);

        bgImage.width = this.stage.stageWidth;
        bgImage.height = this.stage.stageHeight;
        bgImage.x = this.stage.getBounds().x;
        bgImage.y = this.stage.getBounds().y;

        //if(DEBUG) 
        {
            console.log("bgImage.x is ",bgImage.x);
            console.log("bgImage.y is ",bgImage.y);
            console.log("map height is ",bgImage.height * 1 / 5);
        }

        var bit_map_y = 0;

        for(var i: number = 0; i < 5; ++i) {
            bit_map_y = (bgImage.height * 1 / 5) * (i) + 1 * (i + 1);
            {
                console.log("map index is",i,"map y is ",bit_map_y);
            }

            var mapNumber = Math.ceil(Math.random() * 4);

            var map: egret.Bitmap = this.createBitmapByName("map" + mapNumber + "Image");
            this.addChild(map);
            map.x = bgImage.x + 15;
            map.y = bit_map_y;
            map.width = bgImage.width - 25;
            map.height = bgImage.height * 1 / 5;
        }
        
        this.soldier = new Soldier("100005",1);
        
        this.addChild(this.soldier);
    } 
        
     private Update(): void {

        //this.startx -= 33;
        //this.mymc.x = this.startx;
            
        //var tw = egret.Tween.get(this.mybitmap);
        //tw.to({ x: 0 },1000);
    }
    
    private UpdateComplete(): void {
    
    }
    
    private createBitmapByName(name: string): egret.Bitmap {
        var result: egret.Bitmap = new egret.Bitmap();
        var texture: egret.Texture = RES.getRes(name);
        result.texture = texture;
        return result;
    }
}
